package com.ruoyi.web.controller.official;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.official.domain.OfficialBanner;
import com.ruoyi.official.service.IOfficialBannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 官网轮播图Controller
 *
 * @author yuanqiji
 * @date 2025-03-21
 */
@RestController
@RequestMapping("/official/banner")
public class OfficialBannerController extends BaseController {
    @Autowired
    private IOfficialBannerService officialBannerService;

    /**
     * 查询官网轮播图列表
     */
    @PreAuthorize("@ss.hasPermi('official:banner:list')")
    @GetMapping("/list")
    public TableDataInfo list(OfficialBanner officialBanner) {
        startPage();
        List<OfficialBanner> list = officialBannerService.selectOfficialBannerList(officialBanner);
        return getDataTable(list);
    }

    /**
     * 导出官网轮播图列表
     */
    @PreAuthorize("@ss.hasPermi('official:banner:export')")
    @Log(title = "官网轮播图", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OfficialBanner officialBanner) {
        List<OfficialBanner> list = officialBannerService.selectOfficialBannerList(officialBanner);
        ExcelUtil<OfficialBanner> util = new ExcelUtil<OfficialBanner>(OfficialBanner.class);
        util.exportExcel(response, list, "官网轮播图数据");
    }

    /**
     * 获取官网轮播图详细信息
     */
    @PreAuthorize("@ss.hasPermi('official:banner:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return success(officialBannerService.selectOfficialBannerById(id));
    }

    /**
     * 新增官网轮播图
     */
    @PreAuthorize("@ss.hasPermi('official:banner:add')")
    @Log(title = "官网轮播图", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OfficialBanner officialBanner) {
        return toAjax(officialBannerService.insertOfficialBanner(officialBanner));
    }

    /**
     * 修改官网轮播图
     */
    @PreAuthorize("@ss.hasPermi('official:banner:edit')")
    @Log(title = "官网轮播图", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OfficialBanner officialBanner) {
        return toAjax(officialBannerService.updateOfficialBanner(officialBanner));
    }

    /**
     * 删除官网轮播图
     */
    @PreAuthorize("@ss.hasPermi('official:banner:remove')")
    @Log(title = "官网轮播图", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(officialBannerService.deleteOfficialBannerByIds(ids));
    }
}
